package com.example.stars_project_android.index;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.stars_project_android.R;
import com.example.stars_project_android.adapter.MyRoomAdapter;
import com.example.stars_project_android.entity.RoomAppearance;
import com.example.stars_project_android.personalCenter.SetUp;
import com.example.stars_project_android.personalCenter.User;

import java.util.ArrayList;
import java.util.List;

/**
 * 我的房间界面
 */
public class MyRoom extends AppCompatActivity {

    private GridView gridView;
    private List<RoomAppearance> mData = new ArrayList<>();
    private ImageView reRoom;   //返回

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_myroom);

        reRoom = findViewById(R.id.ib_my_room);
        gridView = findViewById(R.id.grid_view);

        //设置数据源
        mData = setData();

        //设置适配器
        MyRoomAdapter mAdapter = new MyRoomAdapter(
                this,
                R.layout.myroom_item,
                mData
        );
        //绑定适配器
        gridView.setAdapter(mAdapter);

        /**
         * gridView的点击事件
         */
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(MyRoom.this, "你点击了~" + position + "~项", Toast.LENGTH_SHORT).show();
            }
        });

        /**
         * 返回按钮的点击事件
         */
        reRoom.setOnClickListener(view->{
            Intent intent = new Intent(this,User.class);
            startActivity(intent);
        });

    }

    /**
     * 设置数据源
     * @return
     */
    private List<RoomAppearance> setData() {
        List<RoomAppearance> list = new ArrayList<>();
        RoomAppearance roomAppearance = new RoomAppearance();
        roomAppearance.setTitle("goWest");
        list.add(roomAppearance);
        return list;
    }
}